package com.mingke.chat.message;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.util.Date;

/**
 * @author mingke
 * @function 消息传递的基类
 * @date 2021/12/18
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public abstract class EasyChatMessage implements Serializable {
    /** 魔数--用以分辨消息的来源，屏蔽掉一些垃圾消息*/
    public static String magic = "zhuhai";
    private static byte magicContent[] = null;
    /** 通讯协议版本号--用以区分不同版本的通讯协议*/
    public static String version = "1.0.1";
    private static byte versionContent[] = null;
    /** 消息时间戳*/
    private Date msgDateTime;

    public static byte[] getMagicContent() {
        if(magicContent == null) {
            magicContent = magic.getBytes(StandardCharsets.UTF_8);
        }
        return magicContent;
    }

    public static byte[] getVersionContent() {
        if(versionContent == null) {
            versionContent = version.getBytes(StandardCharsets.UTF_8);
        }
        return versionContent;
    }

    public Date getMsgDateTime() {
        return msgDateTime;
    }

    public void setMsgDateTime(Date msgDateTime) {
        this.msgDateTime = msgDateTime;
    }
}
